package com.lijian.netty.nio6;

import java.io.FileInputStream;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;

/**
 * @author lj02
 * @desc 传统 io 如何转换为nio  FileInputStream
 * @date 2018/12/1
 */
public class NioTest2 {


    public static void main(String[] args) throws Exception {


        FileInputStream fileInputStream = new FileInputStream("niotest2.txt");

        // 数据在channel 中
        FileChannel channel = fileInputStream.getChannel();

        ByteBuffer buf = ByteBuffer.allocate(512);

        // 数据放到了buf 中
        channel.read(buf);

        buf.flip();

        while (buf.hasRemaining()) {
            byte b = buf.get();

            System.out.print((char) b);
        }

        System.out.println();
        fileInputStream.close();


    }
}
